'''
@Descripttion: 
@version: 
@encoding: utf-8
@Author: qiurongcan
Date: 2025-09-29 17:05:15
LastEditTime: 2025-09-29 17:14:35
'''
# 随机链表的复制


class Solution:

    def copyRandomList(self, head):
        if head is None:
            return None
        
        # 在每一个节点后插入一个相同的节点
        cur = head
        # 复制节点
        while cur:
            cur.next = Node(cur.val, cur.next)
            cur = cur.next.next

        
        cur = head
        # 连接random
        while cur:
            if cur.random:
                cur.next.random = cur.random.next
            
            cur = cur.next.next

        cur = head.next

        while cur.next:
            # 删除节点
            cur.next = cur.next.next
            cur = cur.next
        
        return head.next



